import { productDet } from '@/api'

const state = {
  productData: {},
}

const actions = {
  //商品详细数据
  async getproductDet({ commit }, params) {
    const result = await productDet(params)
    if (result.code === 200) {
      commit('PROD_UCTD_ET', result.result)
    } else {
      console.log(result.message)
    }
  },
}
const mutations = {
  //储存详细数据
  PROD_UCTD_ET(state, payload) {
    state.productData = payload
  },

  //更改放大镜图片和默认图片链接
  UPDATE_IMG_DEFAULT_URL(state, imgUrl) {
    state.goodDetailInfo.skuInfo.skuDefaultImg = imgUrl
  },
}
const getters = {
  categoryView(state) {
    return state.productData.categoryView || {}
  },
  skuInfo(state) {
    return state.productData.skuInfo || {}
  },
  spuSaleAttrList(state) {
    return state.productData.spuSaleAttrList || {}
  },
}
// Vuex中的数据是存储在当前电脑中的内存中的，只要一刷新，就意味着重新加载页面
export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
